package homeWork.day01;

import java.util.Random;
import java.util.Scanner;
public class Test06 {
    public static void main(String[] args) {
        //规定验证码所用字符范围
        String line = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        //调用随机数方法
        Random random=new Random();
        //给验证码初始赋值为空
        String code = "";
        //在line里随机取四个字符组成验证码
        for(int i=0;i<4;i++) {
            int index = random.nextInt(line.length());
            char c = line.charAt(index);
            code += c;
        }
        System.out.println("验证码:"+code);
        //输入验证码
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入验证码:");
        String input = scanner.nextLine();
        //验证验证码
        if(code.equalsIgnoreCase(input)){
            System.out.println("验证成功!");
        }else{
            System.out.println("验证失败!");
        }
    }
}
